package cn.myblog.ainblog.service;

import cn.myblog.ainblog.mapper.LogMapper;
import cn.myblog.ainblog.model.LogModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Dovaior
 * @Description 日志的业务层
 * @create 2021-05-03 15:46
 **/
@Service
public class LogService {
    @Autowired
    private LogMapper logMapper;

    /**
     * 添加日志
     * @param logModel 日志实体类
     * @return 返回标识
     */
    public int insertLog(LogModel logModel){
        return logMapper.insert(logModel);
    }

    /**
     * 查询所有的日志
     * @return 返回list集合
     */
    public List<LogModel> queryAllLog(){
        return logMapper.selectList();
    }

    /**
     * 查询全部种类的操作次数
     * @return 返回封装了全部信息的map
     */
    @Transactional
    public Map<String,Integer> queryAllCount(){
        Map<String,Integer> map = new HashMap();
        map.put("articleCount",logMapper.queryArticleCount());
        map.put("categoryCount",logMapper.queryCategoryCount());
        map.put("tagCount",logMapper.queryTagCount());
        map.put("userCount",logMapper.queryUserCount());
        return map;
    }
}
